﻿using infoMECHANICA.NHibernateORM.TestMappings;
using NHibernate.Criterion;

namespace infoMECHANICA.NHibernateORM.ExampleProgram
{
    /// <summary>
    /// See http://www.codeplex.com/nhcb/Wiki/View.aspx?title=MANY_TO_MANY_QUERIES&referringTitle=Home for details
    /// </summary>
    public class Example3 : IExample
    {
        #region IExample Members

        public string Title
        {
            get { return "Example 3 - many-to-many relationships"; }
        }

        public DetachedCriteria ComposeCriteria()
        {
            // "Employee" restrictions: employee lastname is like 'Smith'
            EmployeeRec employeeRec = new EmployeeRec();
            employeeRec.LastName.SetLike("Smith");

            // "Company" restrictions: we want only these companies where our Smith-employee works
            CompanyRec companyRec = new CompanyRec();
            companyRec.EmployeesByCompany.Exists(employeeRec);

            return companyRec.BuildCriteria();
        }

        #endregion
    }
}
